//
//  DiscoverViewController.m
//  oschina
//
//  Created by 如佳 陈 on 15/5/30.
//  Copyright (c) 2015年 crj. All rights reserved.
//

#import "DiscoverViewController.h"

@interface DiscoverViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSArray *_items;
}

@end

static NSString *identifier = @"discover_cell";
@implementation DiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _items = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"DiscoverConfig" ofType:@"plist"]];
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _items.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return ((NSArray*)_items[section]).count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    [Util setUpTableViewCell:cell];
    cell.textLabel.text = _items[indexPath.section][indexPath.row][@"Desc"];
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"discover-%@",_items[indexPath.section][indexPath.row][@"Name"]]];
    return cell;
}

- (UITableView *)tableView{
    if (!_tableView ) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [Util setUpTableView:_tableView];
    }
    return _tableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
